package  org.cocos2dx.javascript.Advert.gdt;

import android.app.Activity;
import android.util.Log;

import com.qq.e.comm.managers.GDTAdSdk;
import com.qq.e.comm.managers.setting.GlobalSetting;
import org.cocos2dx.javascript.Advert.core.AdSdkComponent;

public class GDTSdkComponent extends AdSdkComponent {

    static Activity curActivity;


    @Override
    public void init(Activity activity) {
        curActivity = activity;
        setSplashAd(new GDTSplashAd());
        setRewardVideoAd(new GDTRewardVideoAd());
        setInterstitialAd(new GDTInterstitialAd());
        setBannerAd(new GDTBannerAd());
        // 建议在初始化 SDK 前进行此设置
        GlobalSetting.setEnableCollectAppInstallStatus(true);
        // 开发者请注意，4.560.1430版本后GDTAdSdk.init接口已废弃，请尽快迁移至GDTAdSdk.initWithoutStart、GDTAdSdk.start
        // GDTAdSdk.init(context, Constants.APPID);
        GDTAdSdk.init(curActivity, GDTConstants.APPID); // 调用此接口进行初始化，该接口不会采集用户信息
        // 调用initWithoutStart后请尽快调用start，否则可能影响广告填充，造成收入下降
        GDTAdSdk.start(new GDTAdSdk.OnStartListener() {
            @Override
            public void onStartSuccess() {
                // 推荐开发者在onStartSuccess回调后开始拉广告
                Log.e("gdt onStartSuccess:", "ok");
                //测试,预加载
                getSplashAd().loadAd(curActivity, true);
                getRewardVideoAd().loadAd(curActivity, false);
                getInterstitialAd().loadAd(curActivity, false);
//                getBannerAd().loadAd(activity, false);
            }

            @Override
            public void onStartFailed(Exception e) {
                Log.e("gdt onStartFailed:", e.toString());
            }
        });
    }
}
